package com.jindun.paper.ui.client;

import org.apache.commons.lang.StringUtils;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerFilter;

import com.jindun.paper.vo.ClientVo;

public class ClientListViewFilter extends ViewerFilter {

	private String searchString;

	public void setSearchText(String s) {
		// ensure that the value can be used for matching
		this.searchString = ".*" + s + ".*";
	}

	@Override
	public boolean select(Viewer viewer, Object parentElement, Object element) {

		ClientVo clientVo = (ClientVo) element;

		if (searchString == null || searchString.length() == 0) {
			return true;
		}
		return StringUtils.isNotBlank(clientVo.getClientName()) && clientVo.getClientName().matches(this.searchString) ||
				StringUtils.isNotBlank(clientVo.getBankAccount()) && clientVo.getBankAccount().matches(this.searchString) ||
				StringUtils.isNotBlank(clientVo.getClientType()) && clientVo.getClientType().matches(searchString) ||
				StringUtils.isNotBlank(clientVo.getFromWhere()) && clientVo.getFromWhere().matches(searchString) ||
				StringUtils.isNotBlank(clientVo.getIdCardNo()) &&  clientVo.getIdCardNo().matches(searchString);
	}

}
